<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="baidu-site-verification" content="zD47G9xe42" />


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="PHP核心编程," />





  <link rel="alternate" href="/atom.xml" title="uiste" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="本章是需要熟记的函数，使用的时候有问题查手册
操作数组的函数is_array()判断一个变量是否是一个数组，返回是一个布尔型，如果是数组返回真，如果不是数组，返回假
array_search()查找一个值是否正在一个数组中，返回的是以键名语法：$arr = array_search(&amp;#39;3&amp;#39;,$arr);

array_search()查找值区分大小写，不区分数据类型，如果出现同值问">
<meta property="og:type" content="article">
<meta property="og:title" content="Day6-php数组、字符串">
<meta property="og:url" content="http://blog.uiste.com/20160827-1.html">
<meta property="og:site_name" content="uiste">
<meta property="og:description" content="本章是需要熟记的函数，使用的时候有问题查手册
操作数组的函数is_array()判断一个变量是否是一个数组，返回是一个布尔型，如果是数组返回真，如果不是数组，返回假
array_search()查找一个值是否正在一个数组中，返回的是以键名语法：$arr = array_search(&amp;#39;3&amp;#39;,$arr);

array_search()查找值区分大小写，不区分数据类型，如果出现同值问">
<meta property="og:updated_time" content="2016-08-27T12:59:57.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Day6-php数组、字符串">
<meta name="twitter:description" content="本章是需要熟记的函数，使用的时候有问题查手册
操作数组的函数is_array()判断一个变量是否是一个数组，返回是一个布尔型，如果是数组返回真，如果不是数组，返回假
array_search()查找一个值是否正在一个数组中，返回的是以键名语法：$arr = array_search(&amp;#39;3&amp;#39;,$arr);

array_search()查找值区分大小写，不区分数据类型，如果出现同值问">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://blog.uiste.com/20160827-1.html"/>

  <title>
 Day6-php数组、字符串 | uiste 
</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?b58b87af012832b8ae35e33bb45b44fa";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">uiste</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">uiste个人博客</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      

            <li class="menu-item menu-item-search"> <a title="把这个链接拖到你的Chrome收藏夹工具栏中" href='javascript:(function() {
    function c() {
        var e = document.createElement("link");
        e.setAttribute("type", "text/css");
        e.setAttribute("rel", "stylesheet");
        e.setAttribute("href", f);
        e.setAttribute("class", l);
        document.body.appendChild(e)
    }
 
    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }
 
    function p() {
        var e = document.createElement("div");
        e.setAttribute("class", a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }
 
    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }
 
    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }
 
    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }
 
    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }
 
    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }
 
    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }
 
    function S() {
        var e = document.createElement("audio");
        e.setAttribute("class", l);
        e.src = i;
        e.loop = false;
        e.addEventListener("canplay", function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener("ended", function() {
            N();
            h()
        }, true);
        e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
        document.body.appendChild(e);
        e.play()
    }
 
    function x(e) {
        e.className += " " + s + " " + o
    }
 
    function T(e) {
        e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
    }
 
    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp("\\b" + s + "\\b");
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, "")
        }
    }
 
    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3";
    var s = "mw-harlem_shake_me";
    var o = "im_first";
    var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
    var a = "mw-strobe_light";
    var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
    var l = "mw_added_css";
    var b = g();
    var w = y();
    var C = document.getElementsByTagName("*");
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn("Could not find a node of the right size. Please try a different page.");
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
})()    '>High</a> </li>

    </ul>
  

 
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
   
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Day6-php数组、字符串
              
            
          </h1>
        

        <div class="post-meta">
        
  <span id="busuanzi_container_page_pv">阅读量 <span id="busuanzi_value_page_pv"></span> 次</span>

          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-08-27T17:18:51+08:00" content="2016-08-27">
              2016-08-27
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/PHP/" itemprop="url" rel="index">
                    <span itemprop="name">PHP</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160827-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160827-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>本章是需要熟记的函数，使用的时候有问题查手册</strong></p>
<h3 id="操作数组的函数"><a href="#操作数组的函数" class="headerlink" title="操作数组的函数"></a>操作数组的函数</h3><h4 id="is-array"><a href="#is-array" class="headerlink" title="is_array()"></a>is_array()</h4><p>判断一个变量是否是一个数组，返回是一个布尔型，如果是数组返回真，如果不是数组，返回假</p>
<h4 id="array-search"><a href="#array-search" class="headerlink" title="array_search()"></a>array_search()</h4><p>查找一个值是否正在一个数组中，返回的是以键名<br>语法：<code>$arr = array_search(&#39;3&#39;,$arr);</code></p>
<blockquote>
<p>array_search()查找值区分大小写，不区分数据类型，如果出现同值问题，取前面第一个下标。<br>第三个参数如果是true则区分数据类型<code>$arr = array_search(&#39;3&#39;,$arr,true);</code></p>
</blockquote>
<h3 id="操作键值的函数"><a href="#操作键值的函数" class="headerlink" title="操作键值的函数"></a>操作键值的函数</h3><h4 id="array-keys"><a href="#array-keys" class="headerlink" title="array_keys()"></a>array_keys()</h4><p>获取数组中的所有下标，以一个索引数组的模式返回<br>语法：<code>$arr2 = array_keys($arr);</code></p>
<blockquote>
<p>获取的数组，下标从0开始依次递增</p>
</blockquote>
<h4 id="array-values"><a href="#array-values" class="headerlink" title="array_values()"></a>array_values()</h4><p>获取数组中的所有值，以一个索引数组的模式返回<br>语法：<code>$arr3 = array_values($arr);</code></p>
<blockquote>
<p>如果值是一个数组，也同样将这个数组当成以值赋值给数组</p>
</blockquote>
<h4 id="array-combine"><a href="#array-combine" class="headerlink" title="array_combine()"></a>array_combine()</h4><p>将两个数组的值合并成一个数组，第一个数组是下标，第二个数组是值<br>语法：<code>$arr4 = array_combine($arr1,$arr2);</code></p>
<blockquote>
<p>返回的数据类型是一个数组。两个数组参数的元素个数必须要一一对应</p>
</blockquote>
<h4 id="in-array"><a href="#in-array" class="headerlink" title="in_array()"></a>in_array()</h4><p>查找数组中的某一个值是否存在<br>语法：<code>var_dump(in_array(&#39;a&#39;,$arr));</code></p>
<blockquote>
<p>in_array查找是区分大小写的，并且默认不区分数据类型，如果想让他区分数据类型，将第三个参数修改为true即可；<br>第一个参数是需要查找的值，第二个参数是查找的数组，返回的结果是一个布尔值<br>而array_search返回的是一个键名</p>
</blockquote>
<h4 id="array-key-exists"><a href="#array-key-exists" class="headerlink" title="array_key_exists()"></a>array_key_exists()</h4><p>查找一个键是否在某个数组中<br>语法：<code>var_dump(array_key_exists(&#39;1&#39;,$arr));</code></p>
<blockquote>
<p>第一个参数是需要查找的下标，第二个参数是需要寻找的数组，返回的结果是一个boolean型<br>本身就不区分数据类型，没有第三个参数；</p>
</blockquote>
<h4 id="isset"><a href="#isset" class="headerlink" title="isset()"></a>isset()</h4><p>判断一个变量是否已经被定义，如果没有被定义或者值为null返回的结果是false<br>语法：<code>var_dump(isset($arr[&#39;b&#39;]));</code></p>
<blockquote>
<p>isset()和array_key_exists的区别，如果下标对应的值为空。isset返回的结果是false，array_key_exists返回的结果是true</p>
</blockquote>
<h3 id="合并和拆分字符、数组的函数"><a href="#合并和拆分字符、数组的函数" class="headerlink" title="合并和拆分字符、数组的函数"></a>合并和拆分字符、数组的函数</h3><h4 id="implode"><a href="#implode" class="headerlink" title="implode()"></a>implode()</h4><p>将一个数组里面的元素合并成一个字符串<br>语法：<code>$str = implode(&#39;&#39;,$arr);</code></p>
<blockquote>
<p>两个参数，第一个是元素值和值之间连接的符号（第一个可以不写），第二个参数是你需要遍历的数组。join()就是implode别名函数</p>
</blockquote>
<h4 id="explode"><a href="#explode" class="headerlink" title="explode()"></a>explode()</h4><p>将一个字符串拆分成一个数组<br>语法：<code>$arr = explode(&#39;a&#39;,$str);</code></p>
<blockquote>
<p>两个参数，第一个是拆分字符串的标志，第二个参数是需要拆分的字符串</p>
</blockquote>
<p>语法：<code>$arr = explode(&#39;a&#39;,$str,3);</code></p>
<blockquote>
<p>如果第三个元素是正整数，分割成三个部分，最后一个元素会将包含剩下的所有的包含<br>如果第三个原始是负整数，则会将最后的3个元素抛弃，</p>
</blockquote>
<h3 id="数组的交并差"><a href="#数组的交并差" class="headerlink" title="数组的交并差"></a>数组的交并差</h3><h4 id="array-merge"><a href="#array-merge" class="headerlink" title="array_merge()"></a>array_merge()</h4><p>合并两个数组：array_merge(数组1,数组2)<br>语法：<code>$arr = array_merge(range(0,9),range(&#39;a&#39;,&#39;z&#39;));</code></p>
<blockquote>
<p>array_merge如果合并两个数字下标的数组，会将数字重新从0进行组合。<br>array_merge如果合并两个字符串下标的数组，后面的值会将前面的值覆盖。<br>array_merge合并两个数组，先从第一个数组开始合并，然后在合并第二个数组。</p>
</blockquote>
<h4 id="array-diff"><a href="#array-diff" class="headerlink" title="array_diff()"></a>array_diff()</h4><p>计算数组差值<br>语法：<code>array array_diff ( array $array1 , array $array2 [, array $... ] )</code></p>
<blockquote>
<p>对比返回在 array1 中但是不在 array2 及任何其它参数数组中的值。<br>返回一个数组，该数组包括了所有在 array1 中但是不在任何其它参数数组中的值。注意键名保留不变</p>
</blockquote>
<h4 id="array-intersect"><a href="#array-intersect" class="headerlink" title="array_intersect()"></a>array_intersect()</h4><p>计算数组的交集<br>语法：<code>array array_intersect ( array $array1 , array $array2 [, array $ ... ] )</code></p>
<blockquote>
<p>array_intersect() 返回一个数组，该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。注意键名保留不变。</p>
</blockquote>
<h3 id="函数遍历数组"><a href="#函数遍历数组" class="headerlink" title="函数遍历数组"></a>函数遍历数组</h3><p>回调函数是由计算机自己去调用php中的函数</p>
<h4 id="array-map"><a href="#array-map" class="headerlink" title="array_map()"></a>array_map()</h4><p>将回调函数作用到给定数组的单元上<br>语法：<code>array array_map ( callable $callback , array $arr1 [, array $... ] )</code><br>语法： array_map(‘函数名’,数组名)。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">//使用系统函数，调用数组</div><div class="line">$arr=array(10,-12,46,-9,-45);</div><div class="line">$arr2 = array_map(&apos;abs&apos;,$arr);</div><div class="line">var_dump($arr2);</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">//使用自身定义的函数，调用数组</div><div class="line">$arr=array(10,-12,46,-9,-45);</div><div class="line">fucntion fn($num)&#123;</div><div class="line">	$num+=10;</div><div class="line">	return $num;</div><div class="line">&#125;</div><div class="line">$arr2 = array_map(&apos;fn&apos;,$arr);</div><div class="line">var_dump($arr2);</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">//使用匿名函数，调用数组</div><div class="line">$arr=array(10,-12,46,-9,-45);</div><div class="line">$arr2 = array_map(function($name)&#123;return &apos;hello&apos;.$name;&#125;,$arr);</div><div class="line">var_dump($arr2);</div></pre></td></tr></table></figure>
<blockquote>
<p>结果将所有数字转换为正数；</p>
<ol>
<li><code>array_map()</code>返回一个数组，该数组包含了 arr1 中的所有单元经过 callback 作用过之后的单元。callback 接受的参数数目应该和传递给 array_map() 函数的数组数目一致。</li>
<li>array_map去回调我们自己定义好的函数</li>
<li>除了第一个参数直接写函数名的方法以外，我们也可以直接写一个匿名函数，达到回调函数的功能</li>
<li>如果第一个参数的值为null，则会把后面的数组的每一个值取出来进行拼接，合并成一个新的数组</li>
</ol>
</blockquote>
<h4 id="array-walk"><a href="#array-walk" class="headerlink" title="array_walk()"></a>array_walk()</h4><p>功能类似于遍历数组，可以同时获取数组里面的值和下标</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">$arr = array(&apos;name&apos;=&gt;&apos;张无忌&apos;,&apos;age&apos;=&gt;528,&apos;sex&apos;=&apos;男&apos;);</div><div class="line">function fn($value,$key)&#123;</div><div class="line">	echo $key.&apos;-&apos;.$value.&apos;&lt;br&gt;&apos;;</div><div class="line">&#125;</div><div class="line">$arr2 = array_walk($arr,&apos;fn&apos;);</div></pre></td></tr></table></figure>
<p>可以分别获取下标和值，进行计算。如果函数只写一个参数，则获取的是数组里面的值。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$arr2 = array_walk($arr,function($value,$key)&#123;</div><div class="line">	echo $key.&apos;-&gt;&apos;.$value,&apos;&lt;br&gt;&apos;;</div><div class="line">&#125;)</div></pre></td></tr></table></figure>
<blockquote>
<p>array_walk同样支持匿名函数的用法</p>
</blockquote>
<ul>
<li><p>接触最多的回调函数还是<code>array_map()，array_walk()</code>用的次数相对于而言，比较少。</p>
</li>
<li><p>array_walk第一个参数写的数组名，第二个参数写的才是调用的数组<br>array_walk返回的结果只会是一个布尔型的结果，如果array_walk执行成功返回的记过就是true，如果array_walk执行失败，返回的救过就是false，他不会生成一个新的数组；</p>
</li>
</ul>
<h3 id="栈和队列"><a href="#栈和队列" class="headerlink" title="栈和队列"></a>栈和队列</h3><p>栈的特点就是先进后出，后进先出。<br>队列的特点就是先进先出，后进后出。</p>
<h4 id="array-push"><a href="#array-push" class="headerlink" title="array_push()"></a>array_push()</h4><p>第一个参数是需要放置的数组，后面的参数是需要放置的元素</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">$arr = array();</div><div class="line">array_push($arr,&apos;a&apos;);</div><div class="line">array_push($arr,&apos;b&apos;,&apos;c&apos;,&apos;d&apos;);</div><div class="line">print_r($arr);</div></pre></td></tr></table></figure>
<blockquote>
<p>一次性可以放置多个元素</p>
</blockquote>
<h4 id="array-pop"><a href="#array-pop" class="headerlink" title="array_pop()"></a>array_pop()</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">$arr = array();</div><div class="line">array_push($arr,&apos;a&apos;);</div><div class="line">array_push($arr,&apos;b&apos;,&apos;c&apos;,&apos;d&apos;);</div><div class="line">array_pop($arr);</div><div class="line">array_pop($arr);</div><div class="line">print_r($arr);</div></pre></td></tr></table></figure>
<blockquote>
<p>出栈一次只能出一个元素。d和c后进的元素，先被拿出来了</p>
</blockquote>
<p>返回结果：mexd,溢出的元素</p>
<h4 id="array-shift"><a href="#array-shift" class="headerlink" title="array_shift()"></a>array_shift()</h4><p>出队列</p>
<blockquote>
<p>思考：unset和arr_shift有什么区别？<br>答案：使用array_shift去移除一个元素，那个其他的元素位置会往前移一位，保持数据完整性；但是unset删除一个元素，下标也会被删除</p>
</blockquote>
<h4 id="array-unshift"><a href="#array-unshift" class="headerlink" title="array_unshift()"></a>array_unshift()</h4><p>就是在数组的第一个位置插入一个元素。</p>
<blockquote>
<p>往数组里面第一个元素的位置放置一个元素。</p>
<p>栈和队列的优点：栈和队列都是有效保证数据的完整性；</p>
</blockquote>
<h3 id="数组的排序"><a href="#数组的排序" class="headerlink" title="数组的排序"></a>数组的排序</h3><h4 id="sort"><a href="#sort" class="headerlink" title="sort()"></a>sort()</h4><p>按照数值值得大小进行排序。从小到大的顺序</p>
<blockquote>
<p>将原有的下标丢弃，从0开始依次递增</p>
</blockquote>
<h4 id="rsort"><a href="#rsort" class="headerlink" title="rsort()"></a>rsort()</h4><p>按照数组的数值进行排序，从大到小的顺序。</p>
<blockquote>
<p>也是将原有的下标丢弃，从0开始依次递增</p>
</blockquote>
<h4 id="asort"><a href="#asort" class="headerlink" title="asort()"></a>asort()</h4><p>按照数组的数值进行排序，从小到大排序，但是会保留下标</p>
<h4 id="arsort"><a href="#arsort" class="headerlink" title="arsort()"></a>arsort()</h4><p>按照数组的数值进行排序，从大到小排序，但是会保留下标</p>
<h4 id="ksort"><a href="#ksort" class="headerlink" title="ksort()"></a>ksort()</h4><p>按照数组的下标顺序进行排序。从小到大进行排序</p>
<h4 id="krsort"><a href="#krsort" class="headerlink" title="krsort()"></a>krsort()</h4><p>按照数组的下标顺序进行排序，从大到小进行排序</p>
<h4 id="natsort"><a href="#natsort" class="headerlink" title="natsort()"></a>natsort()</h4><p>自然排序</p>
<blockquote>
<p>将字符串整体进行排序，而sort会挨个字符进行比较，然后进行排序</p>
</blockquote>
<h4 id="usort"><a href="#usort" class="headerlink" title="usort()"></a>usort()</h4><p>自定义排序</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">$arr = array(</div><div class="line">	array(&apos;name&apos;=&gt;&apos;jack&apos;,&apos;math&apos;=&gt;78,&apos;age&apos;=&gt;56),</div><div class="line">	array(&apos;name&apos;=&gt;&apos;rose&apos;,&apos;math&apos;=&gt;98,&apos;age&apos;=&gt;14),</div><div class="line">	array(&apos;name&apos;=&gt;&apos;jame&apos;,&apos;math&apos;=&gt;56,&apos;age&apos;=&gt;67),</div><div class="line">	array(&apos;name&apos;=&gt;&apos;uiste&apos;,&apos;math&apos;=&gt;45,&apos;age&apos;=&gt;24)</div><div class="line">	);</div><div class="line">usort($arr,function($num1,$num2)&#123;</div><div class="line">	if ($num1[&apos;age&apos;]&gt;$num2[&apos;age&apos;]) &#123;</div><div class="line">		return 1;</div><div class="line">	&#125;elseif ($num1[&apos;age&apos;]&lt;$num2[&apos;age&apos;]) &#123;</div><div class="line">		return -1;</div><div class="line">	&#125;else&#123;</div><div class="line">		return 0;</div><div class="line">	&#125;</div><div class="line">&#125;);</div><div class="line"></div><div class="line">echo &quot;&lt;pre&gt;&quot;;</div><div class="line">print_r($arr);</div><div class="line">echo &quot;&lt;/pre&gt;&quot;;</div></pre></td></tr></table></figure>
<blockquote>
<p>在第一个参数小于，等于或大于第二个参数时，该比较函数必须相应地返回一个小于，等于或大于0的整数。</p>
</blockquote>
<p>如果return -1则值放在前面<br>如果 return 1 则值放在后面<br>如果 return 0 则值的位置不发生变化</p>
<h3 id="关于字符串的函数"><a href="#关于字符串的函数" class="headerlink" title="关于字符串的函数"></a>关于字符串的函数</h3><h4 id=""><a href="#" class="headerlink" title="[]"></a>[]</h4><p>字符串可以理解成字符的合计。</p>
<blockquote>
<p>所以，[]就是获取字符串中的某一个字符</p>
</blockquote>
<h4 id="strlen"><a href="#strlen" class="headerlink" title="strlen()"></a>strlen()</h4><p>获取字符串的长度</p>
<blockquote>
<p>获取长度的单位是字节,中文下的感叹号也被分解为三个字节；空格也在空间</p>
</blockquote>
<h4 id="trim"><a href="#trim" class="headerlink" title="trim()"></a>trim()</h4><p>去除两边的空格</p>
<h4 id="rtrim"><a href="#rtrim" class="headerlink" title="rtrim()"></a>rtrim()</h4><p>除去右边的空格</p>
<h4 id="ltrim"><a href="#ltrim" class="headerlink" title="ltrim()"></a>ltrim()</h4><p>去除左边的空格</p>
<h4 id="strpos"><a href="#strpos" class="headerlink" title="strpos()"></a>strpos()</h4><p>获取字符串某个字符的位置<br>语法：<code>strpos($str,&#39;b&#39;);</code></p>
<blockquote>
<p>获取某个字符首次出现的位置。如果后面加上第三个参数，代表字符串从某个位置开始往后去寻找。如果没写第三个参数，则第三个参数默认为0</p>
</blockquote>
<p>语法：<code>strpos($str,&#39;b&#39;,3);</code></p>
<blockquote>
<p>参数为3，则是从字符串第4个位置开始去寻找</p>
</blockquote>
<h4 id="strrpos"><a href="#strrpos" class="headerlink" title="strrpos()"></a>strrpos()</h4><p>获取某个字符出现的最后一个位置<br>语法：<code>var_dump(strrpo($str,&#39;b&#39;,2));</code></p>
<blockquote>
<p>从右往左查找，第三个参数代表最终查找到某个字符结束。找到返回下标，找不到返回false;</p>
</blockquote>
<h4 id="str-repeat"><a href="#str-repeat" class="headerlink" title="str_repeat()"></a>str_repeat()</h4><p>将某个字符串重复多少次</p>
<blockquote>
<p>第一个参数是需要重复的字符串，第二个参数重复的次数；</p>
</blockquote>
<h4 id="chr"><a href="#chr" class="headerlink" title="chr()"></a>chr()</h4><p>将一个数字转换成ASCII码</p>
<h4 id="ord"><a href="#ord" class="headerlink" title="ord()"></a>ord()</h4><p>将一个ASCII转换成对应的数字</p>
<h4 id="substr"><a href="#substr" class="headerlink" title="substr()"></a>substr()</h4><p>截取某个字符串<br>语法：<code>substr($str,3);</code></p>
<blockquote>
<p>从下标为3的字符开始，一直截取到结束</p>
</blockquote>
<p>语法：<code>substr($str,3,4);</code></p>
<blockquote>
<p>从下标为3的字符开始，截取4个字符</p>
</blockquote>
<p>语法：<code>substr($str,3,-3);</code></p>
<blockquote>
<p>从下标为3的字符开始截取，舍去最后三个字符</p>
</blockquote>
<p>语法：<code>substr($str,-4,2);</code></p>
<blockquote>
<p>从右往左数4个字符开始截取，截取2个</p>
</blockquote>
<p>语法：<code>substr($str,-5,-2);</code></p>
<blockquote>
<p>从右往左数第五个字符开始截取，截取到倒数第二位终止</p>
</blockquote>
<h4 id="strchr"><a href="#strchr" class="headerlink" title="strchr()"></a>strchr()</h4><p>从某个字符开始截取<br>语法：<code>strchr($str,&#39;c&#39;);</code></p>
<blockquote>
<p>从左往右第一个c开始截取到最后（区分大小写）</p>
<p>strstr()的功能和strchr()的功能一模一样，只不过名称不同</p>
</blockquote>
<h4 id="stristr"><a href="#stristr" class="headerlink" title="stristr()"></a>stristr()</h4><p>也是从某个字符开始截取，但是不区分大小写</p>
<h4 id="strrchr"><a href="#strrchr" class="headerlink" title="strrchr()"></a>strrchr()</h4><p>从某个字符最后出现的位置开始往后截取</p>
<blockquote>
<p>可以非常方便的获取文件的后缀名</p>
</blockquote>
<h4 id="str-replace"><a href="#str-replace" class="headerlink" title="str_replace()"></a>str_replace()</h4><p>语法：<code>str_replace(替换前的字符串，替换后的字符串，需要替换的字符串)</code></p>
<h4 id="str-split"><a href="#str-split" class="headerlink" title="str_split()"></a>str_split()</h4><p>分割字符串，生成一个数组</p>
<blockquote>
<p>第一个参数是一个字符串，第二个参数代表以几个字节进行拆分<br>explode是以字符进行拆分的</p>
</blockquote>
<h4 id="str-pad"><a href="#str-pad" class="headerlink" title="str_pad()"></a>str_pad()</h4><p>填充字符串</p>
<blockquote>
<p>四个参数组成，第一个是填充的字符串，第二个是长度，第三个是填充物，第四个是左，右，两边填充</p>
</blockquote>
<h4 id="strtolower"><a href="#strtolower" class="headerlink" title="strtolower()"></a>strtolower()</h4><p>将一个字符串转换成全小写</p>
<h4 id="strtoupper"><a href="#strtoupper" class="headerlink" title="strtoupper()"></a>strtoupper()</h4><p>将一个字符串转换成全大写</p>
<h4 id="nl2br"><a href="#nl2br" class="headerlink" title="nl2br()"></a>nl2br()</h4><p>将\n转换成<br></p>
<h4 id="htmlspecialchars"><a href="#htmlspecialchars" class="headerlink" title="htmlspecialchars():"></a>htmlspecialchars():</h4><p>将标签当成普通文本输出</p>
<h4 id="urlencode"><a href="#urlencode" class="headerlink" title="urlencode()"></a>urlencode()</h4><p>可以将字符串进行加密</p>
<h4 id="urldecode"><a href="#urldecode" class="headerlink" title="urldecode()"></a>urldecode()</h4><p>可以将加密好的字符串进行解码</p>
<h3 id="多字符处理函数"><a href="#多字符处理函数" class="headerlink" title="多字符处理函数"></a>多字符处理函数</h3><p>多字符处理函数，不是php默认的开启模式，需要通过配置php.ini进行操作</p>
<blockquote>
<p>extension=php_mbstring.dll</p>
</blockquote>
<h4 id="mb-strlen"><a href="#mb-strlen" class="headerlink" title="mb_strlen()"></a>mb_strlen()</h4><p>获取字符的长度</p>
<blockquote>
<p>第一个参数是我们需要获取的字符串，第二个参数是选择的编码格式</p>
</blockquote>
<h4 id="mb-internal-encoding"><a href="#mb-internal-encoding" class="headerlink" title="mb_internal_encoding()"></a>mb_internal_encoding()</h4><ul>
<li>获取当前的编码格式（不加参数）</li>
<li>修改当前的编码模式（增加参数）</li>
</ul>
<h4 id="mb-strpos"><a href="#mb-strpos" class="headerlink" title="mb_strpos()"></a>mb_strpos()</h4><p>查找当前某个字符的位置</p>
<h4 id="mb-substr"><a href="#mb-substr" class="headerlink" title="mb_substr()"></a>mb_substr()</h4><p>截取字符</p>
<h4 id="iconv"><a href="#iconv" class="headerlink" title="iconv()"></a>iconv()</h4><p>转换格式</p>
<blockquote>
<p>里面三个参数，第一个是当前的编码，第二个是转换后的编码，第三个是需要转换的字符串</p>
</blockquote>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/PHP核心编程/" rel="tag">#PHP核心编程</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/20160826-1.html" rel="next" title="Day5-php数组相关">
                <i class="fa fa-chevron-left"></i> Day5-php数组相关
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/20160828-1.html" rel="prev" title="php数组比较-usort">
                php数组比较-usort <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- Go to www.addthis.com/dashboard to customize your tools -->
<script type = "text/javascript" src = "//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-57838eee5e2620d0" async = "async" ></script>
      
    </div>
  </div>


          </div>
          

  <p>热评文章</p>
  <div class="ds-top-threads" data-range="weekly" data-num-items="4"></div>


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="20160827-1.html"
           data-title="Day6-php数组、字符串" data-url="http://blog.uiste.com/20160827-1.html">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="uiste" />
          <p class="site-author-name" itemprop="name">uiste</p>
          <p class="site-description motion-element" itemprop="description">Stay Hungry，Stay Foolish</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">55</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/uiste" target="_blank" rel="external nofollow" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/uiste" target="_blank" rel="external nofollow" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/uiste" target="_blank" rel="external nofollow" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.uiste.com" title="uiste 个人博客" target="_blank">uiste 个人博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://uiste.github.io" title="uiste 技术博客" target="_blank">uiste 技术博客</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#操作数组的函数"><span class="nav-number">1.</span> <span class="nav-text">操作数组的函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#is-array"><span class="nav-number">1.1.</span> <span class="nav-text">is_array()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-search"><span class="nav-number">1.2.</span> <span class="nav-text">array_search()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#操作键值的函数"><span class="nav-number">2.</span> <span class="nav-text">操作键值的函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#array-keys"><span class="nav-number">2.1.</span> <span class="nav-text">array_keys()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-values"><span class="nav-number">2.2.</span> <span class="nav-text">array_values()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-combine"><span class="nav-number">2.3.</span> <span class="nav-text">array_combine()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#in-array"><span class="nav-number">2.4.</span> <span class="nav-text">in_array()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-key-exists"><span class="nav-number">2.5.</span> <span class="nav-text">array_key_exists()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#isset"><span class="nav-number">2.6.</span> <span class="nav-text">isset()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#合并和拆分字符、数组的函数"><span class="nav-number">3.</span> <span class="nav-text">合并和拆分字符、数组的函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#implode"><span class="nav-number">3.1.</span> <span class="nav-text">implode()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#explode"><span class="nav-number">3.2.</span> <span class="nav-text">explode()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组的交并差"><span class="nav-number">4.</span> <span class="nav-text">数组的交并差</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#array-merge"><span class="nav-number">4.1.</span> <span class="nav-text">array_merge()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-diff"><span class="nav-number">4.2.</span> <span class="nav-text">array_diff()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-intersect"><span class="nav-number">4.3.</span> <span class="nav-text">array_intersect()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#函数遍历数组"><span class="nav-number">5.</span> <span class="nav-text">函数遍历数组</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#array-map"><span class="nav-number">5.1.</span> <span class="nav-text">array_map()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-walk"><span class="nav-number">5.2.</span> <span class="nav-text">array_walk()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#栈和队列"><span class="nav-number">6.</span> <span class="nav-text">栈和队列</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#array-push"><span class="nav-number">6.1.</span> <span class="nav-text">array_push()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-pop"><span class="nav-number">6.2.</span> <span class="nav-text">array_pop()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-shift"><span class="nav-number">6.3.</span> <span class="nav-text">array_shift()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#array-unshift"><span class="nav-number">6.4.</span> <span class="nav-text">array_unshift()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组的排序"><span class="nav-number">7.</span> <span class="nav-text">数组的排序</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#sort"><span class="nav-number">7.1.</span> <span class="nav-text">sort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#rsort"><span class="nav-number">7.2.</span> <span class="nav-text">rsort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#asort"><span class="nav-number">7.3.</span> <span class="nav-text">asort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#arsort"><span class="nav-number">7.4.</span> <span class="nav-text">arsort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ksort"><span class="nav-number">7.5.</span> <span class="nav-text">ksort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#krsort"><span class="nav-number">7.6.</span> <span class="nav-text">krsort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#natsort"><span class="nav-number">7.7.</span> <span class="nav-text">natsort()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#usort"><span class="nav-number">7.8.</span> <span class="nav-text">usort()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于字符串的函数"><span class="nav-number">8.</span> <span class="nav-text">关于字符串的函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#"><span class="nav-number">8.1.</span> <span class="nav-text">[]</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strlen"><span class="nav-number">8.2.</span> <span class="nav-text">strlen()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#trim"><span class="nav-number">8.3.</span> <span class="nav-text">trim()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#rtrim"><span class="nav-number">8.4.</span> <span class="nav-text">rtrim()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ltrim"><span class="nav-number">8.5.</span> <span class="nav-text">ltrim()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strpos"><span class="nav-number">8.6.</span> <span class="nav-text">strpos()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strrpos"><span class="nav-number">8.7.</span> <span class="nav-text">strrpos()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#str-repeat"><span class="nav-number">8.8.</span> <span class="nav-text">str_repeat()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#chr"><span class="nav-number">8.9.</span> <span class="nav-text">chr()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ord"><span class="nav-number">8.10.</span> <span class="nav-text">ord()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#substr"><span class="nav-number">8.11.</span> <span class="nav-text">substr()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strchr"><span class="nav-number">8.12.</span> <span class="nav-text">strchr()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#stristr"><span class="nav-number">8.13.</span> <span class="nav-text">stristr()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strrchr"><span class="nav-number">8.14.</span> <span class="nav-text">strrchr()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#str-replace"><span class="nav-number">8.15.</span> <span class="nav-text">str_replace()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#str-split"><span class="nav-number">8.16.</span> <span class="nav-text">str_split()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#str-pad"><span class="nav-number">8.17.</span> <span class="nav-text">str_pad()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strtolower"><span class="nav-number">8.18.</span> <span class="nav-text">strtolower()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#strtoupper"><span class="nav-number">8.19.</span> <span class="nav-text">strtoupper()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#nl2br"><span class="nav-number">8.20.</span> <span class="nav-text">nl2br()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#htmlspecialchars"><span class="nav-number">8.21.</span> <span class="nav-text">htmlspecialchars():</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#urlencode"><span class="nav-number">8.22.</span> <span class="nav-text">urlencode()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#urldecode"><span class="nav-number">8.23.</span> <span class="nav-text">urldecode()</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#多字符处理函数"><span class="nav-number">9.</span> <span class="nav-text">多字符处理函数</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#mb-strlen"><span class="nav-number">9.1.</span> <span class="nav-text">mb_strlen()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#mb-internal-encoding"><span class="nav-number">9.2.</span> <span class="nav-text">mb_internal_encoding()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#mb-strpos"><span class="nav-number">9.3.</span> <span class="nav-text">mb_strpos()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#mb-substr"><span class="nav-number">9.4.</span> <span class="nav-text">mb_substr()</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#iconv"><span class="nav-number">9.5.</span> <span class="nav-text">iconv()</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">uiste</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io" rel="external nofollow">Hexo</a> 趋势动力
</div>
<!--站长统计-->
<script src="https://s95.cnzz.com/z_stat.php?id=1259894121&web_id=1259894121" language="JavaScript"></script>
<!--<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next" rel="external nofollow">
    NexT.Mist
  </a>
</div> -->
&nbsp;&nbsp;&nbsp;本站总点击 <span id="busuanzi_value_site_pv"></span> 次
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;您是第 <span id="busuanzi_value_site_uv"></span> 位访客

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<script>
(function(){
    var bp = document.createElement('script');
    bp.src = '//push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"uiste"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/vendors/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });

                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

</body>
</html>
